import { Prop, Provide, Emit, Model } from 'vue-property-decorator';
import { Subject, Subscription } from 'rxjs';
import { UIActionTool,Util,ViewTool } from '@/utils';
<#if !ctrl_base_name??>
<#assign ctrl_base_name = "MainControlBase"/>
</#if>
import { Watch, ${ctrl_base_name} } from '@/studio-core';
<#if ctrl.getPSAppCounterRefs?? && ctrl.getPSAppCounterRefs()??>
<#list ctrl.getPSAppCounterRefs() as singleCounterRef>
<#if singleCounterRef.getPSAppCounter()??>
<#assign appCounter = singleCounterRef.getPSAppCounter()/>
import  ${srfclassname(appCounter.getCodeName())}CounterService  from '@/counter/${srffilepath2(appCounter.getCodeName())}/${srffilepath2(appCounter.getCodeName())}-counter';
</#if>
</#list>
</#if>
<#if appde??>
import ${srfclassname(appde.getCodeName())}Service from '@/service/${srffilepath2(appde.getCodeName())}/${srffilepath2(appde.getCodeName())}-service';
</#if>
import ${srfclassname(ctrl.codeName)}Service from './${srffilepath2(ctrl.codeName)}-${ctrl.getControlType()?lower_case}-service';
<#if ctrl.getPSUIActions?? && ctrl.getPSUIActions()??>
<#list ctrl.getPSUIActions() as uiAction>
<#if uiAction.getPSAppDataEntity()??>
<#assign curAppEntity = uiAction.getPSAppDataEntity()/>
<#if !P.exists("importService", curAppEntity.getId(), "") >
import ${srfclassname(curAppEntity.getCodeName())}UIService from '@/uiservice/${srffilepath2(curAppEntity.getCodeName())}/${srffilepath2(curAppEntity.getCodeName())}-ui-service';
<#if appde?? && (curAppEntity.getId() == appde.getId())><#assign hasAppDE = true /></#if>
</#if>
</#if>
</#list>
</#if>
<#if appde?? && !hasAppDE??>
import ${srfclassname('${appde.getCodeName()}')}UIService from '@/uiservice/${srffilepath2(appde.getCodeName())}/${srffilepath2(appde.getCodeName())}-ui-service';
</#if>
<#--  语言资源入口  -->
<#ibizinclude>
./LANGBASE.vue.ftl
</#ibizinclude>
<#if import_block??>${import_block}</#if>

/**
 * ${ctrl.name}部件基类
 *
 * @export
 * @class ${ctrl_base_name}
 * @extends {${srfclassname(ctrl.codeName)}${srfclassname(ctrl.getControlType()?lower_case)}Base}
 */
export class ${srfclassname(ctrl.codeName)}${srfclassname(ctrl.getControlType()?lower_case)}Base extends ${ctrl_base_name} {

    /**
     * 获取部件类型
     *
     * @protected
     * @type {string}
     * @memberof ${srfclassname(ctrl.codeName)}${srfclassname(ctrl.getControlType()?lower_case)}Base
     */
    protected controlType: string = '${ctrl.getControlType()}';
<#if ctrl.getPSAppCounterRefs?? && ctrl.getPSAppCounterRefs()??>
<#assign counterRefs = ''/>
<#list ctrl.getPSAppCounterRefs() as singleCounterRef>
<#if singleCounterRef.getPSAppCounter()??>
<#assign appCounter = singleCounterRef.getPSAppCounter()/>
    <#assign counterRefs>${counterRefs}this.${appCounter.getCodeName()?lower_case}counterservice<#if singleCounterRef_has_next>,</#if></#assign>
    
    /**
     * ${srfclassname(appCounter.getCodeName())}CounterService计数器服务对象
     *
     * @type {${srfclassname(appCounter.getCodeName())}CounterService}
     * @memberof ${srfclassname(ctrl.codeName)}${srfclassname(ctrl.getControlType()?lower_case)}Base
     */
    public ${appCounter.getCodeName()?lower_case}counterservice: ${srfclassname('${appCounter.getCodeName()}')}CounterService = new ${srfclassname('${appCounter.getCodeName()}')}CounterService({$store: this.$store,context:this.context,viewparams:this.viewparams});
</#if>
</#list>
<#if counterRefs != "">

    /**
     * 计数器服务对象集合
     *
     * @type {Array<*>}
     * @memberof ${srfclassname(ctrl.codeName)}${srfclassname(ctrl.getControlType()?lower_case)}Base
     */    
    public counterServiceArray:Array<any> = [${counterRefs}];
</#if>
</#if>

    /**
     * 建构部件服务对象
     *
     * @type {${srfclassname(ctrl.codeName)}Service}
     * @memberof ${srfclassname(ctrl.codeName)}${srfclassname(ctrl.getControlType()?lower_case)}Base
     */
    public service: ${srfclassname(ctrl.codeName)}Service = new ${srfclassname(ctrl.codeName)}Service({ $store: this.$store });
<#if appde??>

    /**
     * 实体服务对象
     *
     * @type {${srfclassname(appde.getCodeName())}Service}
     * @memberof ${srfclassname(ctrl.codeName)}${srfclassname(ctrl.getControlType()?lower_case)}Base
     */
    public appEntityService: ${srfclassname(appde.getCodeName())}Service = new ${srfclassname(appde.getCodeName())}Service({ $store: this.$store });

    /**
     * 应用实体名称
     *
     * @protected
     * @type {string}
     * @memberof ${srfclassname(ctrl.codeName)}${srfclassname(ctrl.getControlType()?lower_case)}Base
     */
    protected appDeName: string = '${appde.getCodeName()?lower_case}';

    /**
     * 应用实体中文名称
     *
     * @protected
     * @type {string}
     * @memberof ${srfclassname(ctrl.codeName)}${srfclassname(ctrl.getControlType()?lower_case)}Base
     */
    protected appDeLogicName: string = '${ctrl.getPSAppDataEntity().getLogicName()}';

    /**
     * 界面UI服务对象
     *
     * @type {${srfclassname('${appde.getCodeName()}')}UIService}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */  
    public appUIService:${srfclassname('${appde.getCodeName()}')}UIService = new ${srfclassname('${appde.getCodeName()}')}UIService(this.$store);
</#if>
<#if ctrl.getPSControls?? && ctrl.getPSControls()??>
<#list ctrl.getPSControls() as childCtrl>
<#if childCtrl.getControlType()??>
<#if childCtrl.getHookEventNames()??>
<#list childCtrl.getHookEventNames() as eventName>

    /**
     * ${childCtrl.name} 部件 ${eventName?lower_case} 事件
     *
     * @param {*} [args={}]
     * @param {*} $event
     * @memberof ${srfclassname(ctrl.codeName)}${srfclassname(ctrl.getControlType()?lower_case)}Base
     */
    public ${childCtrl.name}_${eventName?lower_case}($event: any, $event2?: any) {
    <#if childCtrl.getPSControlLogics(eventName)??>
    <#list childCtrl.getPSControlLogics(eventName) as ctrlLogic>
    <#if ctrlLogic.getLogicType?? && ctrlLogic.getLogicType() == "APPVIEWENGINE" && ctrlLogic.getPSAppViewEngine()??>
        this.${ctrlLogic.getPSAppViewEngine().getName()}.onCtrlEvent('${childCtrl.name}', '${eventName?lower_case}', $event);
    <#else>
        <#if ctrlLogic.getEventArg()?? && ctrlLogic.getEventArg()?length gt 0>
        if (Object.is($event.tag, '${ctrlLogic.getEventArg()}')) {
            this.${ctrlLogic.name}(null, '<#if ctrlLogic.getLogicTag()?length gt 0>${ctrlLogic.getLogicTag()}</#if>', $event2);
        }
        <#else>
        this.${ctrlLogic.name}($event, '<#if ctrlLogic.getLogicTag()?length gt 0>${ctrlLogic.getLogicTag()}</#if>', $event2);
        </#if>
    </#if>
    </#list>
    </#if>
    }
</#list>
</#if>
</#if>
</#list>
</#if>
<#if ctrl.getPSAppViewLogics?? && ctrl.getPSAppViewLogics()??>
<#list ctrl.getPSAppViewLogics() as logic>
<#if logic.getLogicTrigger() == "CUSTOM" || logic.getLogicTrigger() == "CTRLEVENT">

${P.getLogicCode(logic, "LOGIC.vue").code}
</#if>
</#list>
</#if>
<#if ctrl.getPSUIActions?? && ctrl.getPSUIActions()??>
<#list ctrl.getPSUIActions() as uiAction>
<#if !uiAction.getPSAppDataEntity()??>

${P.getLogicCode(uiAction, "LOGIC.vue").code}
</#if>
</#list>
</#if>

<#if ctrl.render?? && ctrl.render.code2??>
    ${ctrl.render.code2}
</#if>